package com.info.game;




import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.component.game.NullAIComponent;
import com.component.game.NullInputComponent;
import com.component.game.NullRenderComponent;
import com.engine.game.Event;
import com.engine.game.GameEngine;
import com.engine.game.GameFabric;
import com.interpolation.game.NullInterpolator;
import com.level.game.Configuration;
import com.level.game.GameObjectInfo;
import com.level.game.Level;
import com.level.game.StageInfo;
import com.render.game.RenderType;



public class FancyRobotsConfiguration extends Configuration{

	public FancyRobotsConfiguration(GameEngine engine) {
		super(engine);
		
		
	}

	@SuppressWarnings("serial")
	@Override
	protected void createStates() {
		
		this.mapOfStates.put("MENU", new ArrayList<Level>(){
			{
				this.add(new MenuLevel());
			}
		});
		
		this.mapOfStates.put("PLAY", new ArrayList<Level>(){
			{
				this.add(new PlayLevel1());
			}
		});
	}

	@Override
	public void setFirstState() throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
		
		this.currentState = "MENU";
		this.currentLevel = 0;
		
		this.engine.changeTopState(new MenuState(this.engine, new NullInterpolator(), this.mapOfStates.get("MENU").get(0)));
		
	}

	@Override
	public void update() throws InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
		for(Event e : this.events){
			if(e.getMessage().contains("exit")){
				
				
				Gdx.app.exit();
			}
			else if(e.getMessage().contains("key") && e.getMessage().contains("went_down")){
				
				String[] parts = e.getMessage().split(";");
				
				if(parts[1].equals("Escape")){
					Gdx.app.exit();
				}
				
				
				
			}
			else if(e.getMessage().contains("change_menu")){
				
				
				StageInfo.resetID();
				this.engine.changeTopState(new PlayState(this.engine, new NullInterpolator(), this.mapOfStates.get("PLAY").get(0)));
			}
			else if(e.getMessage().contains("create")){
				
				String[] parts = e.getMessage().split(";");
				
				if(parts[1].equals("GRAVITY_ZONE")){
					this.engine.getTopState().addGameObject(GameFabric.createGameObject(this.engine.getTopState(), 
							new GameObjectInfo("GRAVITY_ZONE", NullInputComponent.class.getCanonicalName(), NullAIComponent.class.getCanonicalName(),
									GravityZonePhysicsComponent.class.getCanonicalName(), NullRenderComponent.class.getCanonicalName(), false, 
									this.engine.getTopState().getStageID("GRAVITY_ROBOT"), RenderType.no_type, -1)));
				}
			}
			else if(e.getMessage().contains("die")){
				
				String[] parts = e.getMessage().split(";");
				
				this.engine.getTopState().getGameObject(parts[1]).die();
			}

		}
		
		this.clearEvents();
		
	}

	


}
